# -*- coding: utf-8 -*-
"""
@author: Y.Wang
"""

import sys
import os
import subprocess

#C:/Users/Gabe/Desktop/Workspace/Python/NukeREST/TacticNuke
# /home/viki/huaiweiNuke/shots/ep01/seq01/sc001/RND/publish/beauty/ep01_01_001.beauty.####.tif
class TacticNuke():
    def build(self, name, basepath, master_basepath, master_nukepath):

        try:
            nukepath = '"C:\Program Files\Nuke9.0v7\Nuke9.0.exe"' #确定此处是否正确
            nukeOPPath="D:\WorkSpace\Python\NukeREST\TacticNuke\NukeOPAPI.py"
            # cmd=nukepath+" -t NukeOPAPI.py "+"\""+str(name)+"\" \""+str(basepath)+"\" \""+str(master_basepath)+"\" \""+str(master_nukepath)+"\""
            cmd = nukepath + " -t "+nukeOPPath+" " + str(name) + " " + str(basepath) + " " + str(master_basepath) + " " + str(master_nukepath)
            # cmd=nukepath+" -t "
            print cmd
            #ps=os.Popen(str(cmd),stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=False)
            ps = os.popen(str(cmd))
            output = str(ps.read()).split("\n")
            # filePath=ps.read().split('\n')
            filePath = output[-2]

            print filePath
            flag = 0
            for i in output:
                print i
                if "false false" in str(i):
                    flag = 1
                else:
                    continue

            if flag == 1:
                return "False"
            else:
                return str(filePath)

        except:
            return "False"